package com.team2.outpatient_sys.dao;

import com.team2.outpatient_sys.pojo.Dispense;
import com.team2.outpatient_sys.pojo.Medicine;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface DispenseDao {

    @Insert("insert into dispense values(null,#{prescriptionId},#{dispenseTime})")
    public Integer add(Dispense dispense);

    @Delete("delete from dispense where id=#{id}")
    public Integer delete(Integer id);

    @Update("update dispense set prescription_id = #{prescriptionId},dispense_time=#{dispenseTime} where id={id}")
    public Integer update(Dispense dispense);

    @Select("select * from dispense")
    public List<Dispense> findAll();

    @Select("select * from dispense where id=#{id}")
    public Dispense findById(Integer id);

    //根据处方ID查询处方的药品信息
    @Select("SELECT medicine.*\n" +
            "FROM medicine, prescription_medicine, prescription\n" +
            "WHERE medicine.id = prescription_medicine.medicine_id AND prescription_medicine.prescription_id = prescription.id\n" +
            "AND prescription.id=#{prescriptionId}")
    public List<Medicine> findDispense(Integer prescriptionId);

}